# Contributor: Jim Killingsworth <jkillingsworth@gmail.com>

_realname=ttfautohint
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.4
pkgrel=1
pkgdesc="Automated hinting tools for TrueType fonts (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.freetype.org/ttfautohint/"
license=(GPL2+ custom:FreeType)
depends=("${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' '!libtool' 'staticlibs')
source=("https://download.savannah.gnu.org/releases/freetype/${_realname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('8a876117fa6ebfd2ffe1b3682a9a98c802c0f47189f57d3db4b99774206832e1'
            'SKIP')
validpgpkeys=('58E0C111E39F5408C5D3EC76C1A60EACE707FDA5') # Werner Lemberg <wl@gnu.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # VERSION file is being picked up by #include <version> inside libc++
  rm -f VERSION
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mv "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  ./configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  # Licenses
  install -Dm644 "${srcdir}/build-${MSYSTEM}/COPYING"   "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/build-${MSYSTEM}/GPLv2.TXT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPLv2.TXT"
  install -Dm644 "${srcdir}/build-${MSYSTEM}/FTL.TXT"   "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/FTL.TXT"
}
